package com.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pojo.User;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author:周鹏
 * @date: 2020/11/23 16:05
 * @description：json格式互转工具类
 */
public class JsonUtils {
    public static String  getJson(Object obj,String dateformat)  {
        //jackson对象映射器
        ObjectMapper mapper=new ObjectMapper();
        SimpleDateFormat df=new SimpleDateFormat(dateformat);
//        String dt=df.format(obj);
//        System.out.println(dt);
//        mapper.setDateFormat(df);
        try {
            return mapper.writeValueAsString(df.format(obj));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    return  null;
    }
    public static String getJson(Object obj) throws JsonProcessingException {

       return getJson(obj,"yyyy-MM-dd HH:mm:ss");
    }


}
